<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Album
 * @copyright  Copyright 2006-2010 Webligo Developments
 * @license    http://www.socialengine.net/license/
 * @version    $Id: view.tpl 9330 2011-09-27 23:33:35Z john $
 * @author     John Boehr <j@webligo.com>
 */
?>

<?php
  $this->headScript()
    ->appendFile($this->layout()->staticBaseUrl . 'externals/moolasso/Lasso.js')
    ->appendFile($this->layout()->staticBaseUrl . 'externals/moolasso/Lasso.Crop.js')
    ->appendFile($this->layout()->staticBaseUrl . 'externals/autocompleter/Observer.js')
    ->appendFile($this->layout()->staticBaseUrl . 'externals/autocompleter/Autocompleter.js')
    ->appendFile($this->layout()->staticBaseUrl . 'externals/autocompleter/Autocompleter.Local.js')
    ->appendFile($this->layout()->staticBaseUrl . 'externals/autocompleter/Autocompleter.Request.js')
    ->appendFile($this->layout()->staticBaseUrl . 'externals/tagger/tagger.js')
    ->appendFile($this->layout()->staticBaseUrl . 'application/modules/Album/externals/scripts/core.js');
  $this->headTranslate(array(
    'Save', 'Cancel', 'delete',
  ));
?>

<script type="text/javascript">
  en4.core.runonce.add(function() {
    var descEls = $$('.albums_viewmedia_info_caption');
    if( descEls.length > 0 ) {
      descEls[0].enableLinks();
    }

    var taggerInstance_photo = window.taggerInstance_photo = new Tagger('media_photo_next_view', {
      'title' : '<?php echo $this->string()->escapeJavascript($this->translate('ADD TAG'));?>',
      'description' : '<?php echo $this->string()->escapeJavascript($this->translate('Type a tag or select a name from the list.'));?>',
      'createRequestOptions' : {
        'url' : '<?php echo $this->url(array('module' => 'core', 'controller' => 'tag', 'action' => 'add'), 'default', true) ?>',
        'data' : {
          'subject' : '<?php echo $this->subject()->getGuid() ?>'
        }
      },
      'deleteRequestOptions' : {
        'url' : '<?php echo $this->url(array('module' => 'core', 'controller' => 'tag', 'action' => 'remove'), 'default', true) ?>',
        'data' : {
          'subject' : '<?php echo $this->subject()->getGuid() ?>'
        }
      },
      'cropOptions' : {
        'container' : $('media_photo_next_view')
      },
      'tagListElement' : 'media_tags_view',
      'existingTags' : <?php echo Zend_Json::encode($this->tags) ?>,
      'suggestProto' : 'request.json',
      'suggestParam' : "<?php echo $this->url(array('module' => 'user', 'controller' => 'friends', 'action' => 'suggest', 'includeSelf' => true), 'default', true) ?>",
      'guid' : <?php echo ( $this->viewer()->getIdentity() ? "'".$this->viewer()->getGuid()."'" : 'false' ) ?>,
      'enableCreate' : <?php echo ( $this->canTag ? 'true' : 'false') ?>,
      'enableDelete' : <?php echo ( $this->canUntagGlobal ? 'true' : 'false') ?>
    });

    // Remove the href attrib while tagging
    var nextHref = $('media_photo_next_view').get('href');
    taggerInstance_photo.addEvents({
      'onBegin' : function() {
        $('media_photo_next_view').erase('href');
      },
      'onEnd' : function() {
        $('media_photo_next_view').set('href', nextHref);
      }
    });
    
    var keyupEvent = function(e) {
     if(!$$('.lightface')[0]){
        if( e.key == 'right' ) {
          if($('photo_next_view'))
          window.location.href = "<?php echo ( $this->nextPhoto ? $this->nextPhoto->getHref() : 'window.location.href' ) ?>";
        } else if( e.key == 'left' ) {
          if($('photo_prev_view'))
          window.location.href = "<?php echo ( $this->previousPhoto ? $this->previousPhoto->getHref() : 'window.location.href' ) ?>";
        }
      }
    }
    $$('html').removeEvent('keyup').addEvent('keyup', keyupEvent);
    // Add shutdown handler
    en4.core.shutdown.add(function() {
      window.removeEvent('keyup', keyupEvent);
    });

	var pos = $('albums_viewmedia').getPosition();
	$$('body')[0].scrollTo(pos.x, pos.y);  

	//edit-photo area
		if($('frmEditPhoto_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>')) $('frmEditPhoto_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>').addEvent('submit', function(e){
			e.stop();
			var form_values  = $('frmEditPhoto_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>').toQueryString();
	        	form_values += '&format=json';
	        en4.core.request.send(new Request.JSON({
	    	    url : en4.core.baseUrl + 'ialbum/photo/quick-edit',
	    	    data : form_values,
	    	    onSuccess : function(responseTree, responseElements, responseHTML, responseJavaScript) {
	    	    	window.location.reload(true);
		    	}
	    	}));
		});	
	 if($('aEdit_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>')) $('aEdit_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>').removeClass('disableEdit');
	 $('titlePhotoValue_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>').addEvents({
		'focus': function(){
			if (this.value.contains('<?php echo $this->translate('Write a title...')?>')) this.value = '';
		},
		'blur': function(){
			if (this.value == '') this.value = '<?php echo $this->translate('Write a title...')?>';
		}
	 });
	 
	 $('desPhotoValue_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>').addEvents({
			'focus': function(){
				if (this.value.contains('<?php echo $this->translate('Write a description...')?>')) this.value = '';
			},
			'blur': function(){
				if (this.value == '') this.value = '<?php echo $this->translate('Write a description...')?>';
			}
		});
  });
  function editPhoto_view(obj, isShow){
		if(isShow){
			$('headerBox_'+obj.get('class')).hide();
			$('boxEdit_'+obj.get('class')).show();
			if($('aEdit_'+obj.get('class')))  $('aEdit_'+obj.get('class')).addClass('disableEdit');
		}else{
			$('headerBox_'+obj.get('class')).show();
			$('boxEdit_'+obj.get('class')).hide();
			if($('aEdit_'+obj.get('class'))) $('aEdit_'+obj.get('class')).removeClass('disableEdit');
		}
	}
</script>


<div class="layout_middle">
<div class='albums_viewmedia' id="albums_viewmedia">
  <?php if( !$this->message_view): ?>
  <div>
	<h2 class="headerTitle" ><?php echo $this->album->getTitle()?></h2>
 </div>
  <div class="albums_viewmedia_nav">
    <div>
       <a href="<?php echo $this->album->getHref();?>"><?php echo $this->translate('Back to album')?></a>
       <?php if(!$this->mine):?>
       -
       <a href="<?php echo $this->url(array('action'=>'show', 'user_id'=>$this->album->owner_id), 'album_general', true);?>"><?php echo $this->translate('%1$s\'s Photos', $this->album->getOwner()->getTitle()); ?></a>
       - 
       <a href="<?php echo $this->album->getOwner()->getHref();?>"><?php echo $this->translate('%1$s\'s Profile', $this->album->getOwner()->getTitle()); ?></a>
       <?php else:?>
       - <a href="<?php echo $this->url(array('action'=>'show', 'user_id'=>$this->album->owner_id), 'album_general', true);?>"><?php echo $this->translate('My Photos'); ?></a>
       <?php endif;?> 
    </div>
    <?php if( $this->album->count() > 1 ): ?>
    <div>
      <?php echo $this->htmlLink(( $this->previousPhoto ? $this->previousPhoto->getHref() : null ), $this->translate('Previous'), array('id' => 'photo_prev_view')) ?>
      -
      <?php echo $this->htmlLink(( $this->nextPhoto ? $this->nextPhoto->getHref() : null ), $this->translate('Next'), array('id' => 'photo_next_view')) ?>
    </div>
    <?php endif ?>
  </div>
  <?php endif ?>
  <div class='albums_viewmedia_info'>
    <div class='album_viewmedia_container' id='media_photo_div_view'>
      <a id='media_photo_next_view'  href='<?php echo $this->nextPhoto ? $this->escape($this->nextPhoto->getHref()) : '#' ?>'>
        <?php echo $this->htmlImage($this->photo->getPhotoUrl(), $this->photo->getTitle(), array(
          'id' => 'media_photo'
        )); ?>
      </a>
    </div>
    <?php if( $this->canTag ): ?>
    <a class="tags_button" onclick="taggerInstance_photo.begin();">
    	<span ><?php echo $this->translate('Tag Photo');?></span>
    </a>
    <?php endif;?>
    <?php if($this->canComment):?>
    <span class="likes_comment_buttons">
    	<span class="likes_button">
    			<a id="likeAlbum" onclick="en4.ialbum.comments.like('<?php echo $this->subject()->getType()?>', '<?php echo $this->subject()->getIdentity() ?>')" href="javascript:void(0);" style="display: <?php echo ($this->subject()->likes()->isLike($this->viewer()))?'none': '';?>">
    				<?php echo $this->translate('Like')?>
    			</a>
				
				<a  onclick="en4.ialbum.comments.unlike('<?php echo $this->subject()->getType()?>', '<?php echo $this->subject()->getIdentity() ?>')" id="unLikeAlbum" href="javascript:void(0);" style="display: <?php echo ($this->subject()->likes()->isLike($this->viewer()))?'': 'none;';?>">
    				<?php echo $this->translate('Unlike')?>
    			</a>
				
    	</span>
    	<span class="comment_button" onclick="$('commentBodyOver_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>').focus();">
    		<a  href="javascript:void(0);"><?php echo $this->translate('Comment')?></a>
    	</span>
    </span>  
    <?php endif;?> 
  </div>

</div>
<div class="albums_viewinfos">
	<div class="albums_left">
		<div class="image_block">
			<?php echo $this->htmlLink($this->album->getOwner(), $this->itemPhoto($this->album->getOwner(), 'thumb.icon'), array('class' => 'profilePhoto'));?>
		</div>
		<div class="block_content">
		  <div id="headerBox_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>">
			<?php echo $this->htmlLink($this->album->getOwner(), $this->album->getOwner()->getTitle(), array('class' => 'profileTitle'));?>
			<div>
				<?php if($this->photo->getTitle()):?>
					<div class="albums_viewmedia_info_title"><?php echo $this->photo->getTitle()?></div>
				<?php endif;?> 
			   <?php $isWith = false; if( $this->photo->getDescription() ): $isWith = true;?>		       			   
		     	<span>
		        <?php echo nl2br($this->photo->getDescription()) ?>
		       </span>
			    <?php else: $isWith = false;
			    	endif;	
			    ?>
			    <span class="albums_viewmedia_info_tags" id="media_tags_view" style="display: none;">
		      		<?php echo ($isWith)?'&nbsp;&ndash;&nbsp;'. $this->translate('with ') : $this->translate('With ');?>
		    	</span>
	    	</div>
	    </div>
	    	<?php if($this->canEdit):?>
	    	<form id="frmEditPhoto_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>" name="frmEditPhoto" method="post" enctype="application/x-www-form-urlencoded">
		    	<div class="boxEdit" id="boxEdit_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>" style="display: none;">
		    		<div class="photoTitle gen">
		    			<input class="titlePhotoValue" id="titlePhotoValue_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>" class="textInput" type="text" name="title" value="<?php echo ($this->photo->getTitle())? $this->photo->getTitle() : $this->translate('Write a title...');?>">
		    		</div>
		    		<div class="photoDes gen">
		    			<textarea id="desPhotoValue_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>" name="description" id="photoDesArea_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>" class="areaDes"><?php echo ($this->photo->getDescription()) ? $this->photo->getDescription() : $this->translate('Write a description...')?></textarea>
		    		</div>
		    		<input type="hidden" value="<?php echo $this->album->getIdentity()?>" name="album_id">
		    		<input type="hidden" value="<?php echo $this->photo->getIdentity()?>" name="photo_id">
					<div class="editActions">
						<button type="submit" name="submit" ><?php echo $this->translate('Save changes');?></button>
						<button type="button" name="cancel" onclick="editPhoto_view(this, false);" class="<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>"><?php echo $this->translate('Cancel'); ?></button>
					</div>		    	
		    	</div>
		    </form>
	    	<?php endif;?>
    		<?php 
				$api = Engine_Api::_()->getApi('Content', 'Ialbum');
				echo $api->getWidgetComment();
					 $api->clearLayout();
				unset ($api);
			?> 
		</div>
	</div>
	<div class="albums_right">
		<div class="media_infos">
			<div>
				<span class="label"><?php echo $this->translate('Album');?>:</span> 
				<?php echo $this->htmlLink($this->album, $this->album->getTitle());?>
				&nbsp;&ndash;&nbsp;
				 <span class="navigator_number">
				   <?php 
					  echo $this->translate('%1$s of %2$s',
					  $this->locale()->toNumber($this->photo->getPhotoIndex() + 1),
					  $this->locale()->toNumber($this->album->count())) 
				  ?>
				  </span>	 
			</div>

		</div>
		<?php if( $this->canTag ): ?>
		<div class="boder_over mt pt">
			<a class="photo_tags actions_item" onclick='taggerInstance_photo.begin();' href="javascript: void(0);">
				<i class="mrs img icon_tags"></i>
				<span><?php echo $this->translate('Tag this photo')?></span>
			</a>
		</div>
		<?php endif;?>			
		<div class="boder_over mt pt media_actions">
			<a class="actions_item" href="<?php echo $this->url(array('module'=>'ialbum', 'controller'=>'index', 'action'=>'download-image', 'photo_id'=>$this->photo->getIdentity()), 'default', true);?>">
				<span><?php echo $this->translate('Download')?></span>
			</a>
			<?php if ($this->viewer()->getIdentity()):?>
			<?php if( !$this->message_view ):?>
				<a class="actions_item smoothbox" href="<?php echo $this->url(array('controller' => 'edit', 'action' => 'external-photo', 'photo' => $this->photo->getGuid()), 'user_extended', true);?>">
					<span><?php echo $this->translate('Make Profile Picture')?></span>
				</a>
				<a class="actions_item smoothbox" href="<?php echo $this->url(array('module'=> 'core', 'controller' => 'report', 'action' => 'create', 'subject' => $this->photo->getGuid()), 'default');?>">
					<span><?php echo $this->translate('Report This Photo')?></span>
				</a>
			<?php endif;?>
			<?php if( $this->canDelete ): ?>
         		<?php echo $this->htmlLink(array('reset' => false, 'action' => 'delete'), $this->translate('Delete'), array('class' => 'smoothbox actions_item')) ?>
        	<?php endif; ?>
        	<?php endif;?>
		</div>
	  <?php if( $this->canEdit ): ?>
	      <div class="boder_over mt pt albums_viewmedia_info_actions" style="font-size: 10pt;">
	        <a class="buttonlink icon_photos_rotate_ccw" href="javascript:void(0)" onclick="$(this).set('class', 'buttonlink icon_loading');en4.album.rotate(<?php echo $this->photo->getIdentity() ?>, 90).addEvent('complete', function(){ this.set('class', 'buttonlink icon_photos_rotate_ccw') }.bind(this));">&nbsp;</a>
	        <a class="buttonlink icon_photos_rotate_cw" href="javascript:void(0)" onclick="$(this).set('class', 'buttonlink icon_loading');en4.album.rotate(<?php echo $this->photo->getIdentity() ?>, 270).addEvent('complete', function(){ this.set('class', 'buttonlink icon_photos_rotate_cw') }.bind(this));">&nbsp;</a>
	        <a class="buttonlink icon_photos_flip_horizontal" href="javascript:void(0)" onclick="$(this).set('class', 'buttonlink icon_loading');en4.album.flip(<?php echo $this->photo->getIdentity() ?>, 'horizontal').addEvent('complete', function(){ this.set('class', 'buttonlink icon_photos_flip_horizontal') }.bind(this));">&nbsp;</a>
	        <a class="buttonlink icon_photos_flip_vertical" href="javascript:void(0)" onclick="$(this).set('class', 'buttonlink icon_loading');en4.album.flip(<?php echo $this->photo->getIdentity() ?>, 'vertical').addEvent('complete', function(){ this.set('class', 'buttonlink icon_photos_flip_vertical') }.bind(this));">&nbsp;</a>
	      </div>
      <?php endif ?>
	</div>
</div>
</div>